<template>
  <div>
    <!-- nav -->
    <van-nav-bar title="城市列表" left-arrow @click-left="$router.back()" />
    <!--list -->
      <van-index-bar>
        <van-index-anchor/>
        <van-cell
        v-for="(v,index) in allList"
        :key="index"
        :title="v.label"
        @click="inFn(v)"
        />
      </van-index-bar>
  </div>
</template>

<script>
import { getCityList } from '@/api/home'
import { setCityName } from '@/utils/storage'
export default {
  data () {
    return {
      allList: [],
      newList: [
        'A',
        'B',
        'C',
        'D',
        'E',
        'F',
        'G',
        'H',
        'I',
        'J',
        'K',
        'L',
        'M',
        'N',
        'O',
        'P',
        'Q',
        'R',
        'S',
        'T',
        'U',
        'V',
        'W',
        'X',
        'Y',
        'Z'
      ]
    }
  },
  async created () {
    const list = await getCityList()
    // 获取所有一级城市列表
    this.allList = list.body
  },
  methods: {
    inFn (v) {
      // 存名并返回index
      setCityName(v.label)
      this.$router.back()
    }
  }
}
</script>

<style lang="less" scoped>
.van-nav-bar {
  position: fixed;
  top: 0px;
  left: 0px;
  height: 46px;
  width: 375px;
  background-color: #59b67f;
}

</style>
